package com.yxw.live_vod_boot.controller;

import com.yxw.live_vod_boot.dto.collection_video.OnDemandCollectionVideoAddDTO;
import com.yxw.live_vod_boot.dto.collection_video.OnDemandCollectionVideoDeleteDTO;
import com.yxw.live_vod_boot.dto.collection_video.OnDemandCollectionVideoQueryDTO;
import com.yxw.live_vod_boot.dto.collection_video.OnDemandCollectionVideoSingleQueryDTO;
import com.yxw.live_vod_boot.service.OnDemandCollectionVideoService;
import com.yxw.live_vod_boot.vo.CollectionStateVO;
import com.yxw.live_vod_boot.vo.OnDemandCollectionVideoVO;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author fangmaoxin
 * &#064;date  2023年11月16日
 */
@RestController
@Api(value = "点播收藏视频管理", tags = "收藏-视频管理")
@Slf4j
@RequestMapping("/api/collectionVideo")
public class OnDemandCollectionVideoController {

    @Autowired
    private OnDemandCollectionVideoService collectionVideoService;

    /**
     * 用户查询自己的收藏视频列表
     */
    @PostMapping("/getCollectionVideoByUserId")
    @ApiOperation("用户查询自己的收藏视频列表")
    public BaseResult<PageVO<OnDemandCollectionVideoVO>> list(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionVideoQueryDTO dto) {
        PageVO<OnDemandCollectionVideoVO> collectionList = collectionVideoService.getCollectionVideoByUserId(userId, dto);
        return ResultHelper.fillWithSuccess(collectionList);
    }

    /**
     * 用户新增一个收藏视频
     */
    @PostMapping("/insertCollectionVideoByUserId")
    @ApiOperation("用户收藏视频/再次点击取消收藏")
    public BaseResult insertCollectionVideoByUserId(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionVideoAddDTO dto) {
        return BaseResult.doSuccess(collectionVideoService.insertCollectionVideoByUserId(userId, dto), "操作成功！");
    }

    /**
     * 用户删除一个收藏视频
     */
    @PostMapping("/deleteCollectionVideoByUserId")
    @ApiOperation("用户删除一个收藏视频")
    public BaseResult deleteCollectionVideoByUserId(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionVideoDeleteDTO dto) {
        return BaseResult.doSuccess(collectionVideoService.deleteCollectionVideoByUserId(userId, dto), "视频已成功从收藏列表删除！");
    }

    /**
     * 用户查询自己有没有收藏某个视频
     */
    @PostMapping("/checkCollectionStateForUser")
    @ApiOperation("用户查询自己有没有收藏某个视频")
    public BaseResult<CollectionStateVO> checkCollectionStateForUser(@RequestParam("userId") Long userId, @RequestBody @Validated OnDemandCollectionVideoSingleQueryDTO dto) {
        CollectionStateVO result = collectionVideoService.checkCollectionStateForUser(userId, dto);
        return BaseResult.doSuccess(result, "操作成功！");
    }

}